
(function (obj) {


    let messageCount2_OBJ

    function messageCount2(obj) {

        messageCount2_OBJ = obj
        let objID = obj.id
        bottomInit(objID)
        document.getElementById(objID).style.backgroundColor = "rgba(102,102,153,.8)"
        document.getElementById(objID).style.color = "rgb(255,255,255)"
        document.getElementById(objID).style.boxShadow = "0 0 0 white"
        document.getElementById(objID).style.border = "2px solid rgba(204,204,204,1)"
        let span = document.getElementById(objID).getElementsByTagName("span")
        for (const spanElement of span) {
            if (spanElement.getAttribute("name") === "badge") {
                spanElement.setAttribute("hidden", "true")
            }
        }
        $("#messageCenterText0001").text("业务类型选择")

        $.ajax({
            url: "/messageCenter/getBMMessageMenu",
            type: "POST",
            dataType: "JSON",
            success: function (result) {
                if (result.flag) {
                    let arr = result.data

                    for (const arrElement of arr) {
                        let str = '<div style="display: inline-block; ;margin-left: 6%;float: left" onclick="' + arrElement.bmFun + '">'
                            + '<div class="imgSc">'
                            + '<span style="font-size: 10px;float: right;background-color: #fa5a57 ;color: white  ;font-family: \'Microsoft YaHei UI\',serif" name="badge" class="badge badge-light" id="BMbadge' + arrElement.bmId + '" >1</span>'
                            + '<img class="cardImg" style="opacity: .8;border-radius: 25px" src=' + arrElement.imgurl + '  height="130" width="120">'
                            + '<br id="one1">'
                            + '<span class="cardText">'
                            + arrElement.bmName
                            + '</span>'
                            + '</div>'
                            + '</div>'

                        $("#messageSidBar_ul0001").append(str)

                    }
                } else {
                    $("#messageCenterText0001").text(result.errorMsg)
                    $("#messageCenterText0001").css("color", "orange")
                    setTimeout(function () {
                        $("#messageCenterText0001").text("系统消息")
                        $("#messageCenterText0001").css("color", "rgb(255,255,255)")
                    }, 3000)
                }
            },
            complete: function () {
                $.post("/messageCenter/getBMMessageMenuCount", {}, function (resultCount) {
                    let scaddAuditMessageCount = resultCount.data.scaddAuditMessageCount;
                    let scdailyAuditMessageCount = resultCount.data.scdailyAuditMessageCount;
                    let scdailyExMessageCount = resultCount.data.scdailyExMessageCount;


                    if (scaddAuditMessageCount > 0) {
                        document.getElementById("BMbadge" + "1").style.visibility = "visible"
                        if (scaddAuditMessageCount < 100) {
                            document.getElementById("BMbadge" + "1").innerText = scaddAuditMessageCount
                        } else {
                            document.getElementById("BMbadge" + "1").innerText = "99+"
                        }
                    } else {
                        document.getElementById("BMbadge" + "1").style.visibility = "hidden"
                    }

                    if (scdailyAuditMessageCount > 0) {
                        document.getElementById("BMbadge" + "2").style.visibility = "visible"
                        if (scdailyAuditMessageCount < 100) {
                            document.getElementById("BMbadge" + "2").innerText = scdailyAuditMessageCount
                        } else {
                            document.getElementById("BMbadge" + "2").innerText = "99+"
                        }
                    } else {
                        document.getElementById("BMbadge" + "2").style.visibility = "hidden"
                    }


                    if (scdailyExMessageCount > 0) {
                        document.getElementById("BMbadge" + "3").style.visibility = "visible"
                        if (scdailyExMessageCount < 100) {
                            document.getElementById("BMbadge" + "3").innerText = scdailyExMessageCount
                        } else {
                            document.getElementById("BMbadge" + "3").innerText = "99+"
                        }
                    } else {
                        document.getElementById("BMbadge" + "3").style.visibility = "hidden"
                    }

                })
            }
        })


    }

    function bm_fun_SCAdd(obj) {
        $("#messageSidBar_ul0001").empty()
        document.getElementById("messageCenterText00").innerText = "返回"
        document.getElementById("messageCenterText00").style.width = "40%"
        document.getElementById("messageCenterText00").style.textAlign = "center"
        document.getElementById("messagePageIcon").setAttribute("src", "/static/Img/PageImg/MessageCenterReturn.png")
        document.getElementById("card_Li_00").onclick = returnBtn;
        document.getElementById("messageCenterText0001").innerText = "点检项目添加消息"

        $.post("/messageCenter/messageContext_S_C_Audit", {}, function (result) {

            console.log(result)
            let index = 0;
            if (result.flag) {
                for (const datum of result.data) {
                    index++
                    let cardDiv = document.createElement("div")
                    cardDiv.setAttribute("id", "cardDiv" + index)
                    cardDiv.className = "cardDiv shadow-sm bg-white rounded"

                    let userAuditMessageImage = document.createElement("div")
                    userAuditMessageImage.className = "userAuditMessageImage"
                    userAuditMessageImage.innerText = "SCA"

                    let CardMessageDiv1 = document.createElement("div")
                    CardMessageDiv1.className = "CardMessageDiv1"

                    let messageName = document.createElement("span")
                    messageName.className = "userAuditMessageName text-muted"
                    messageName.innerText = "点检项目添加"

                    let itemName = document.createElement("span")
                    itemName.className = "SCAddItemName"
                    itemName.innerText = "项目名:" + datum.itemName


                    let fullName = document.createElement("span")
                    fullName.className = "SCAddFullName SCAddItemName"
                    fullName.innerText = "申请人:" + datum.lastUserEntity.fullname

                    let group1 = GetGroup();
                    let group = document.createElement("span")
                    group.className = "SCAddGroup SCAddItemName"
                    for (const groupElement of group1) {
                        if (groupElement.groupContext === datum.mongoDB_s_c_point_contentEntityS[0].group_type) {

                            group.innerText = "项目归属:" + groupElement.groupAlias
                        }
                    }

                    let CardMessageDiv2 = document.createElement("div")
                    CardMessageDiv2.className = "CardMessageDiv1 CardMessageDiv2"

                    let sonItem = document.createElement("span")
                    sonItem.className = "SCAddItemName"
                    sonItem.innerText = "子项:" + datum.mongoDB_s_c_point_contentEntityS.length

                    let month = datum.month
                    let day = datum.day
                    let hour = datum.hour
                    let minute = datum.minute

                    if (hour < 10) {
                        hour = '0' + hour
                    }
                    if (minute < 10) {
                        minute = '0' + minute
                    }
                    let time = month + "月" + day + "日" + " " + hour + ":" + minute
                    let itemTime = document.createElement("span")
                    itemTime.className = "SCAddFullName SCAddItemName"
                    itemTime.innerText = "添加时间:" + time

                    CardMessageDiv2.appendChild(sonItem)
                    CardMessageDiv2.appendChild(itemTime)


                    itemName.onmouseover = function () {
                        itemName.style.width = "auto"
                        sonItem.style.visibility = "hidden"
                    }
                    itemName.onmouseout = function () {
                        itemName.style.width = "100%"
                        sonItem.style.visibility = "visible"
                    }

                    let actionDiv = document.createElement("div")
                    actionDiv.className = "actionDiv"


                    let auditPassBtn = document.createElement("button")
                    auditPassBtn.className = "btn btn-success auditPassBtn"
                    auditPassBtn.innerText = "详细"
                    auditPassBtn.setAttribute("id", "SCAddDetailedBtnFun")
                    auditPassBtn.addEventListener("click", function () {
                        SCAddDetailedBtnFun(datum.itemName, index)
                    })

                    let auditNGBtn = document.createElement("button")
                    auditNGBtn.className = "btn btn-warning auditNGBtn"
                    auditNGBtn.innerText = "驳回"
                    auditNGBtn.setAttribute("id", "SCAddNGBtn")
                    auditNGBtn.addEventListener("click", function () {
                        SCAddNGBtnFun(datum.itemName, index)
                    })
                    CardMessageDiv1.appendChild(itemName)
                    CardMessageDiv1.appendChild(fullName)
                    CardMessageDiv1.appendChild(group)

                    cardDiv.appendChild(userAuditMessageImage)
                    cardDiv.appendChild(messageName)
                    cardDiv.appendChild(CardMessageDiv1)
                    cardDiv.appendChild(CardMessageDiv2)

                    actionDiv.appendChild(auditPassBtn)
                    actionDiv.appendChild(auditNGBtn)
                    cardDiv.appendChild(actionDiv)

                    document.getElementById("messageSidBar_ul0001").appendChild(cardDiv)
                }

            } else {

            }

        })

    }


    function returnBtn() {
        messageCount2(messageCount2_OBJ)
        document.getElementById("messageCenterText00").innerText = "消息中心"
        document.getElementById("messageCenterText00").style.width = "auto"
        document.getElementById("messageCenterText00").style.textAlign = "center"
        document.getElementById("messagePageIcon").setAttribute("src", "/static/Img/PageImg/plane.png")
        document.getElementById("card_Li_00").onclick = gotoMessageCenter;
    }

    function SCAddNGBtnFun(itemName, index) {


        $.post("/Spot_Check_Audit/sportAudit", {itemName: itemName, status: "ReviewNG"}, function (result) {
            if (result.flag) {
                document.getElementById("cardDiv" + index).remove()
                bm_fun_SCAdd()
                messageCount()


                $("#messageCenterText0001").text(result.errorMsg)
                $("#messageCenterText0001").css("color", "orange")
                setTimeout(function () {
                    $("#messageCenterText0001").text("点检添加审核消息")
                    $("#messageCenterText0001").css("color", "rgb(255,255,255)")
                }, 3000)
            } else {
                $("#messageCenterText0001").text(result.errorMsg)
                $("#messageCenterText0001").css("color", "orange")
                setTimeout(function () {
                    $("#messageCenterText0001").text("点检添加审核消息")
                    $("#messageCenterText0001").css("color", "rgb(255,255,255)")
                }, 3000)

            }
        })

    }

    function returnSCAddBtn() {
        bm_fun_SCAdd()
        $("#messageSidBar_ul02").empty()
        getSidBar()
    }

    function SCAddDetailedBtnFun(itemName, index) {
        document.getElementById("messageCenterText0001").innerText = itemName
        $("#messageSidBar_ul0001").empty()
        let sidBarEle = document.getElementById("card_Li_02")


        document.getElementById("messageCenterText00").innerText = "返回"
        document.getElementById("messageCenterText00").style.width = "40%"
        document.getElementById("messageCenterText00").style.textAlign = "center"
        document.getElementById("messagePageIcon").setAttribute("src", "/static/Img/PageImg/MessageCenterReturn.png")
        document.getElementById("card_Li_00").onclick = returnSCAddBtn;

        $.post("/Spot_Check_Audit/audit", {itemName: itemName}, function (result) {
            if (result.flag) {
                let pass = '<li onclick="passButton(\'' + itemName + '\')"  class="card_Li01 passButton" id="passButton"  >'
                    + '                         <span  class="messageCenterText" >通过</span>'
                    + '                     </li>'
                ;
                let ng = '<li onclick="ngButton(\'' + result.data.length + ',' + itemName + '\')"  class="card_Li01 ngButton" id="ngButton"  >'
                    + '                         <span  class="messageCenterText" >驳回</span>'
                    + '                     </li>'
                ;
                $(ng).insertAfter($("#card_Li_02"))
                $(pass).insertAfter($("#card_Li_02"))
                let i = 0
                for (const datum of result.data) {
                    i++


                    let cardDiv = document.createElement("div")
                    cardDiv.setAttribute("id", "cardDiv" + index)
                    cardDiv.className = "cardDiv shadow-sm bg-white rounded"

                    let userAuditMessageImage = document.createElement("div")
                    userAuditMessageImage.className = "userAuditMessageImage"
                    userAuditMessageImage.innerText = "D" + datum.pointContentId

                    let CardMessageDiv1 = document.createElement("div")
                    CardMessageDiv1.className = "CardMessageDiv1"

                    let messageName = document.createElement("span")
                    messageName.className = "userAuditMessageName text-muted"
                    messageName.innerText = "详细审核"

                    let SCItem = document.createElement("span")
                    SCItem.className = "SCAddItemName"
                    SCItem.innerText = "点检内容:" + datum.pointContent


                    let scFun = document.createElement("span")
                    scFun.className = "SCAddItemName SCAddFullName"
                    if (datum.scFun === null) {
                        scFun.innerText = "点检方法:无"
                    } else {
                        scFun.innerText = "点检方法:" + datum.scFun
                    }
                    let scBenchmark = document.createElement("span")
                    scBenchmark.className = "SCAddItemName SCAddGroup"
                    if (datum.scBenchmark === null) {
                        scBenchmark.innerText = "点检基准:无"
                    } else {
                        scBenchmark.innerText = "点检基准:" + datum.scBenchmark
                    }

                    let CardMessageDiv2 = document.createElement("div")
                    CardMessageDiv2.className = "CardMessageDiv1 CardMessageDiv2"

                    let SCImg = document.createElement("img")
                    SCImg.className = 'SCImg'
                    let staticTempPath = "/Spot_check/TempImage/"

                    if (datum.imageName === "null.jpeg") {
                        SCImg.src = "/static/Img/PageImg/Canva.png"
                        SCItem.onmouseover = function () {
                            SCItem.style.width = "auto"
                            SCImg.style.visibility = "hidden"
                        }
                        SCItem.onmouseout = function () {
                            SCItem.style.width = "100%"
                            SCImg.style.visibility = "visible"
                        }
                    } else {
                        SCImg.src = staticTempPath + datum.imageName
                        SCImg.onmouseover = function () {
                            SCImg.style.width = "9em"
                            SCImg.style.height = "9em"
                            SCImg.style.zIndex = "9999"
                        }
                        SCImg.onmouseout = function () {
                            SCImg.style.width = "5em"
                            SCImg.style.height = "5em"
                            SCImg.style.zIndex = "0"
                        }

                        SCItem.onmouseover = function () {
                            SCItem.style.width = "auto"
                            SCImg.style.visibility = "hidden"
                        }
                        SCItem.onmouseout = function () {
                            SCItem.style.width = "100%"
                            SCImg.style.visibility = "visible"
                        }
                    }


                    let CardMessageDiv3 = document.createElement("div")
                    CardMessageDiv3.className = "CardMessageDiv1 CardMessageDiv3"


                    /*<div class="form-group">
                        <label for="exampleFormControlTextarea1">Example textarea</label>
                        <textarea class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
                      </div>*/


                    let remarkContext_label = document.createElement("label")
                    remarkContext_label.for = "remarkContext"
                    remarkContext_label.style.display = "block"
                    let remarkContext = document.createElement("textarea")
                    remarkContext.className = "form-control"
                    remarkContext.id = "remarkContext" + i
                    remarkContext.rows = 3
                    remarkContext.style.display = "inline-block"
                    remarkContext.placeholder = "如需驳回,在此输入修改意见"
                    remarkContext.style.fontSize = "xx-small"

                    CardMessageDiv3.appendChild(remarkContext_label)
                    CardMessageDiv3.appendChild(remarkContext)


                    CardMessageDiv2.appendChild(SCImg)


                    CardMessageDiv1.appendChild(SCItem)
                    CardMessageDiv1.appendChild(scFun)
                    CardMessageDiv1.appendChild(scBenchmark)

                    cardDiv.appendChild(userAuditMessageImage)
                    cardDiv.appendChild(messageName)
                    cardDiv.appendChild(CardMessageDiv1)
                    cardDiv.appendChild(CardMessageDiv2)
                    cardDiv.appendChild(CardMessageDiv3)
                    /*cardDiv.appendChild(CardMessageDiv2)*/

                    /*actionDiv.appendChild(auditPassBtn)
                    actionDiv.appendChild(auditNGBtn)
                    cardDiv.appendChild(actionDiv)*/

                    document.getElementById("messageSidBar_ul0001").appendChild(cardDiv)
                }
            }
        })


    }

    function passButton(itemName) {

        $.post("/Spot_Check_Audit/detailedAuditsPass", {ItemName: itemName}, function (result) {

        })

        messageCount2(messageCount2_OBJ)

    }

    function ngButton(obj) {
        let strS;
        let arr = obj.split(",")
        let id = arr[0]
        let valueArr = [];

        for (let i = 0; i < id; i++) {

            let remarkContextId = "remarkContext" + (i + 1);
            console.log(remarkContextId)
            console.log(document.getElementById(remarkContextId))
            let value = document.getElementById(remarkContextId).value
            if (value === "") {
                valueArr.push("thisNull")
            } else {
                valueArr.push(value)
            }
            strS = valueArr.join(",");

        }

        $.post("/Spot_Check_Audit/detailedAudits", {
            itemName: arr[1],
            status: "ReviewNG",
            remarkContext: strS
        }, function (result) {

        })
        messageCount2(messageCount2_OBJ)


    }

    // 点检项目添加结束


    //日常点检审核 开始

    let bm_fun_SCDailyAuth_scdatesEntityS;

    function bm_fun_SCDailyAuth(obj) {
        bm_fun_SCDailyAuth_scdatesEntityS = []

        $("#messageSidBar_ul0001").empty()
        document.getElementById("messageCenterText00").innerText = "返回"
        document.getElementById("messageCenterText00").style.width = "40%"
        document.getElementById("messageCenterText00").style.textAlign = "center"
        document.getElementById("messagePageIcon").setAttribute("src", "/static/Img/PageImg/MessageCenterReturn.png")
        document.getElementById("card_Li_00").onclick = returnBtn;
        document.getElementById("messageCenterText0001").innerText = "日常点检审核"

        $.post("/messageCenter/findS_C_DailyAuditMessage", {}, function (result) {
            let index = 0;
            if (result.flag) {
                bm_fun_SCDailyAuth_scdatesEntityS = result.data
                for (const datum of result.data) {
                    index++
                    //早班
                    if (datum.scdatesEntityS[0].morningAuditUid === null && datum.scdatesEntityS[0].pointContentMorningUid != null) {
                        let cardDiv = document.createElement("div")
                        cardDiv.setAttribute("id", "cardDiv" + index)
                        cardDiv.className = "cardDiv shadow-sm bg-white rounded"

                        let userAuditMessageImage = document.createElement("div")
                        userAuditMessageImage.className = "userAuditMessageImage"
                        userAuditMessageImage.innerText = "SCD"

                        let CardMessageDiv1 = document.createElement("div")
                        CardMessageDiv1.className = "CardMessageDiv1"

                        let messageName = document.createElement("span")
                        messageName.className = "userAuditMessageName text-muted"
                        messageName.innerText = "日常点检审核"

                        let itemName = document.createElement("span")
                        itemName.className = "SCAddItemName"
                        itemName.innerText = "点检点位: " + datum.scdatesEntityS[0].point


                        let fullName = GetUser(datum.scdatesEntityS[0].pointContentMorningUid)
                        let SCUser = document.createElement("span")
                        SCUser.className = "SCAddFullName SCAddItemName"
                        SCUser.innerText = "点检人: " + fullName.fullname

                        let SCSailings = document.createElement("span")
                        SCSailings.className = "SCAddGroup SCAddItemName"
                        SCSailings.innerText = "班次: 早班"

                        let CardMessageDiv2 = document.createElement("div")
                        CardMessageDiv2.className = "CardMessageDiv1 CardMessageDiv2"

                        let SCTime = document.createElement("span")
                        SCTime.className = "SCAddItemName"
                        SCTime.innerText = "点检日期: " + new Date(datum.scdatesEntityS[0].date).toLocaleDateString()


                        let SCStatus = document.createElement("span")
                        SCStatus.className = "SCAddFullName SCAddItemName"
                        SCStatus.innerText = "点位状态: "

                        let statusPoint = document.createElement("span")
                        statusPoint.className = "statusPoint"

                        let statusContext = document.createElement("span")
                        statusContext.className = "SCAddItemName statusContext"

                        SCStatus.appendChild(statusPoint)
                        SCStatus.appendChild(statusContext)
                        let flag = true
                        let breakFlag = false;
                        for (const scdatesEntity of datum.scdatesEntityS) {
                            if (scdatesEntity.pointContentMorningStatusId !== null) {
                                if (flag) {
                                    if (scdatesEntity.pointContentMorningStatusId === 1) {
                                        //正常
                                        statusPoint.style.backgroundColor = "green"
                                        statusContext.innerText = "正常"

                                    } else {
                                        if (scdatesEntity.pointContentMorningStatusId === 2) {
                                            //异常
                                            statusPoint.style.backgroundColor = "orange"
                                            statusContext.innerText = "异常"
                                            flag = false
                                        } else if (scdatesEntity.pointContentMorningStatusId === 3) {
                                            //重大异常
                                            statusPoint.style.backgroundColor = "red"
                                            statusContext.innerText = "重大异常"
                                            flag = false
                                            breakFlag = true
                                        }
                                    }
                                } else {
                                    if (scdatesEntity.pointContentMorningStatusId === 2) {
                                        //异常
                                        statusPoint.style.backgroundColor = "orange"
                                        statusContext.innerText = "异常"
                                        flag = false
                                    } else if (scdatesEntity.pointContentMorningStatusId === 3) {
                                        //重大异常
                                        statusPoint.style.backgroundColor = "red"
                                        statusContext.innerText = "重大异常"
                                        flag = false
                                        breakFlag = true
                                    }
                                }
                            }
                            if (breakFlag) {
                                break
                            }
                        }
                        let exceptionCorrespondence = document.createElement("span")
                        exceptionCorrespondence.className = "SCAddGroup SCAddItemName"
                        if (!flag) {
                            if (datum.scdatesEntityS[0].morningExceptionCorrespondence === null) {
                                exceptionCorrespondence.innerText = "异常对应: 暂无对应"
                            } else {
                                exceptionCorrespondence.innerText = "异常对应: " + datum.scdatesEntityS[0].morningExceptionCorrespondence
                            }

                        }

                        let CardMessageDiv3 = document.createElement("div")
                        CardMessageDiv3.className = "CardMessageDiv1 CardMessageDiv3"

                        let SCDailyDetailedBtn = document.createElement("button")
                        SCDailyDetailedBtn.className = "btn btn-info auditNGBtn"
                        SCDailyDetailedBtn.innerText = "详细"
                        SCDailyDetailedBtn.setAttribute("id", "auditPassBtn")
                        SCDailyDetailedBtn.addEventListener("click", function () {
                            SCDailyDetailedBtnFun("早班", datum.scdatesEntityS[0].date, datum.scdatesEntityS[0].point)
                        })

                        let SCDailyPassBtn = document.createElement("button")
                        if (flag) {
                            SCDailyPassBtn.className = "btn btn-success auditPassBtn"
                            SCDailyPassBtn.innerText = "通过"
                            SCDailyPassBtn.setAttribute("id", "SCDailyPassBtn")
                            SCDailyPassBtn.addEventListener("click", function () {
                                SCDailyPassBtnFun("早班", datum.scdatesEntityS[0].date, datum.scdatesEntityS[0].point)
                            })
                            CardMessageDiv3.appendChild(SCDailyPassBtn)
                        }


                        CardMessageDiv1.appendChild(itemName)
                        CardMessageDiv1.appendChild(SCUser)
                        CardMessageDiv1.appendChild(SCSailings)

                        CardMessageDiv2.appendChild(SCTime)
                        CardMessageDiv2.appendChild(SCStatus)
                        CardMessageDiv2.appendChild(exceptionCorrespondence)

                        CardMessageDiv3.appendChild(SCDailyDetailedBtn)

                        /*CardMessageDiv1.appendChild(fullName)
                        CardMessageDiv1.appendChild(group)*/

                        cardDiv.appendChild(userAuditMessageImage)
                        cardDiv.appendChild(messageName)
                        cardDiv.appendChild(CardMessageDiv1)
                        cardDiv.appendChild(CardMessageDiv2)
                        cardDiv.appendChild(CardMessageDiv3)

                        /*actionDiv.appendChild(auditPassBtn)
                        actionDiv.appendChild(auditNGBtn)
                        cardDiv.appendChild(actionDiv)*/

                        document.getElementById("messageSidBar_ul0001").appendChild(cardDiv)
                    }
                    //中班
                    if (datum.scdatesEntityS[0].middayAuditUid === null && datum.scdatesEntityS[0].pointContentMiddayUid != null) {
                        let cardDiv = document.createElement("div")
                        cardDiv.setAttribute("id", "cardDiv" + index)
                        cardDiv.className = "cardDiv shadow-sm bg-white rounded"

                        let userAuditMessageImage = document.createElement("div")
                        userAuditMessageImage.className = "userAuditMessageImage"
                        userAuditMessageImage.innerText = "SCD"

                        let CardMessageDiv1 = document.createElement("div")
                        CardMessageDiv1.className = "CardMessageDiv1"

                        let messageName = document.createElement("span")
                        messageName.className = "userAuditMessageName text-muted"
                        messageName.innerText = "日常点检审核"

                        let itemName = document.createElement("span")
                        itemName.className = "SCAddItemName"
                        itemName.innerText = "点检点位: " + datum.scdatesEntityS[0].point

                        let fullNameS = GetUser(datum.scdatesEntityS[0].pointContentMiddayUid)
                        let SCUser = document.createElement("span")
                        SCUser.className = "SCAddFullName SCAddItemName"
                        SCUser.innerText = "点检人: " + fullNameS.fullname

                        let SCSailings = document.createElement("span")
                        SCSailings.className = "SCAddGroup SCAddItemName"
                        SCSailings.innerText = "班次: 中班"

                        let CardMessageDiv2 = document.createElement("div")
                        CardMessageDiv2.className = "CardMessageDiv1 CardMessageDiv2"

                        let SCTime = document.createElement("span")
                        SCTime.className = "SCAddItemName"
                        SCTime.innerText = "点检日期: " + new Date(datum.scdatesEntityS[0].date).toLocaleDateString()

                        let SCStatus = document.createElement("span")
                        SCStatus.className = "SCAddFullName SCAddItemName"
                        SCStatus.innerText = "点位状态: "

                        let statusPoint = document.createElement("span")
                        statusPoint.className = "statusPoint"

                        let statusContext = document.createElement("span")
                        statusContext.className = "SCAddItemName statusContext"

                        SCStatus.appendChild(statusPoint)
                        SCStatus.appendChild(statusContext)
                        let flag = true
                        let breakFlag = false;
                        for (const scdatesEntity of datum.scdatesEntityS) {
                            if (scdatesEntity.pointContentMiddayStatusId !== null) {
                                if (flag) {
                                    if (scdatesEntity.pointContentMiddayStatusId === 1) {
                                        //正常
                                        statusPoint.style.backgroundColor = "green"
                                        statusContext.innerText = "正常"

                                    } else {
                                        if (scdatesEntity.pointContentMiddayStatusId === 2) {
                                            //异常
                                            statusPoint.style.backgroundColor = "orange"
                                            statusContext.innerText = "异常"
                                            flag = false
                                        } else if (scdatesEntity.pointContentMiddayStatusId === 3) {
                                            //重大异常
                                            statusPoint.style.backgroundColor = "red"
                                            statusContext.innerText = "重大异常"
                                            flag = false
                                            breakFlag = true
                                        }
                                    }
                                } else {
                                    if (scdatesEntity.pointContentMiddayStatusId === 2) {
                                        //异常
                                        statusPoint.style.backgroundColor = "orange"
                                        statusContext.innerText = "异常"
                                        flag = false
                                    } else if (scdatesEntity.pointContentMiddayStatusId === 3) {
                                        //重大异常
                                        statusPoint.style.backgroundColor = "red"
                                        statusContext.innerText = "重大异常"
                                        flag = false
                                        breakFlag = true;
                                    }
                                }
                            }
                            if (breakFlag) {
                                break
                            }
                        }
                        let exceptionCorrespondence = document.createElement("span")
                        exceptionCorrespondence.className = "SCAddGroup SCAddItemName"
                        if (!flag) {
                            if (datum.scdatesEntityS[0].morningExceptionCorrespondence === null) {
                                exceptionCorrespondence.innerText = "异常对应: 暂无对应"
                            } else {
                                exceptionCorrespondence.innerText = "异常对应: " + datum.scdatesEntityS[0].morningExceptionCorrespondence
                            }

                        }

                        let CardMessageDiv3 = document.createElement("div")
                        CardMessageDiv3.className = "CardMessageDiv1 CardMessageDiv3"

                        let SCDailyDetailedBtn = document.createElement("button")
                        SCDailyDetailedBtn.className = "btn btn-info auditNGBtn"
                        SCDailyDetailedBtn.innerText = "详细"
                        SCDailyDetailedBtn.setAttribute("id", "auditPassBtn")
                        SCDailyDetailedBtn.addEventListener("click", function () {
                            SCDailyDetailedBtnFun("中班", datum.scdatesEntityS[0].date, datum.scdatesEntityS[0].point)
                        })

                        let SCDailyPassBtn = document.createElement("button")
                        if (flag) {
                            SCDailyPassBtn.className = "btn btn-success auditPassBtn"
                            SCDailyPassBtn.innerText = "通过"
                            SCDailyPassBtn.setAttribute("id", "SCDailyPassBtn")
                            SCDailyPassBtn.addEventListener("click", function () {
                                SCDailyPassBtnFun("中班", datum.scdatesEntityS[0].date, datum.scdatesEntityS[0].point)
                            })
                            CardMessageDiv3.appendChild(SCDailyPassBtn)
                        }


                        CardMessageDiv1.appendChild(itemName)
                        CardMessageDiv1.appendChild(SCUser)
                        CardMessageDiv1.appendChild(SCSailings)

                        CardMessageDiv2.appendChild(SCTime)
                        CardMessageDiv2.appendChild(SCStatus)
                        CardMessageDiv2.appendChild(exceptionCorrespondence)

                        CardMessageDiv3.appendChild(SCDailyDetailedBtn)

                        /*CardMessageDiv1.appendChild(fullName)
                        CardMessageDiv1.appendChild(group)*/

                        cardDiv.appendChild(userAuditMessageImage)
                        cardDiv.appendChild(messageName)
                        cardDiv.appendChild(CardMessageDiv1)
                        cardDiv.appendChild(CardMessageDiv2)
                        cardDiv.appendChild(CardMessageDiv3)

                        /*actionDiv.appendChild(auditPassBtn)
                        actionDiv.appendChild(auditNGBtn)
                        cardDiv.appendChild(actionDiv)*/

                        document.getElementById("messageSidBar_ul0001").appendChild(cardDiv)
                    }

                }
            }
        })
    }

    //点检通过
    function SCDailyPassBtnFun(SCSailings, date, pointName) {
        $.ajax({
            url: "/Spot_Check_Audit/sCDailyPass",
            type: "post",
            dataType: "json",
            data: {SCSailings: SCSailings, date: date, pointName: pointName},
            success: function (result) {
                if (result.flag) {
                    bm_fun_SCDailyAuth()
                } else {
                    let messageCenterText0001 = document.getElementById("messageCenterText0001")
                    let afterMessage = messageCenterText0001.innerText
                    messageCenterText0001.innerText = result.errorMsg
                    setTimeout(function () {
                        messageCenterText0001.innerText = afterMessage
                    }, 5000)
                }

            }
        })
    }

    //点检详细
    function SCDailyDetailedBtnFun(SCSailings, date, pointName) {
        $("#messageSidBar_ul0001").empty()
        for (const bmFunSCDailyAuthScdatesEntity of bm_fun_SCDailyAuth_scdatesEntityS) {
            if (SCSailings === "早班") {
                if (bmFunSCDailyAuthScdatesEntity.scdatesEntityS[0].point === pointName && bmFunSCDailyAuthScdatesEntity.scdatesEntityS[0].date === date) {
                    let index = 0;
                    for (const bmFunSCDailyAuthScdatesEntityElement of bmFunSCDailyAuthScdatesEntity.scdatesEntityS) {
                        index++
                        let cardDiv = document.createElement("div")
                        cardDiv.setAttribute("id", "cardDiv" + index)
                        cardDiv.className = "cardDiv shadow-sm bg-white rounded"

                        let userAuditMessageImage = document.createElement("div")
                        userAuditMessageImage.className = "userAuditMessageImage"
                        userAuditMessageImage.innerText = "D" + index

                        let CardMessageDiv1 = document.createElement("div")
                        CardMessageDiv1.className = "CardMessageDiv1"

                        let messageName = document.createElement("span")
                        messageName.className = "userAuditMessageName text-muted"
                        messageName.innerText = "日常点检详细"

                        let sCTime = document.createElement("span")
                        sCTime.className = "SCAddItemName"
                        sCTime.innerText = "点检日期: " + new Date(date).toLocaleDateString()

                        let pointName = document.createElement("span")
                        pointName.className = "SCAddItemName SCAddFullName"
                        pointName.innerText = "点检内容: " + bmFunSCDailyAuthScdatesEntityElement.pointContent

                        let fullNameS = GetUser(bmFunSCDailyAuthScdatesEntityElement.pointContentMorningUid)
                        let sCUser = document.createElement("span")
                        sCUser.className = "SCAddItemName SCAddGroup"
                        sCUser.innerText = "点检人: " + fullNameS.fullname

                        let CardMessageDiv2 = document.createElement("div")
                        CardMessageDiv2.className = "CardMessageDiv1 CardMessageDiv2"

                        let SCStatus = document.createElement("span")
                        SCStatus.className = "SCAddItemName"
                        SCStatus.innerText = "点检状态"

                        let statusPoint = document.createElement("span")
                        statusPoint.className = "statusPoint"

                        let statusContext = document.createElement("span")
                        statusContext.className = "SCAddItemName statusContext"

                        let flag = false
                        if (bmFunSCDailyAuthScdatesEntityElement.pointContentMorningStatusId === 1) {
                            statusPoint.style.backgroundColor = "green"
                            statusContext.innerText = "正常"
                            flag = true
                        } else if (bmFunSCDailyAuthScdatesEntityElement.pointContentMorningStatusId === 2) {
                            statusPoint.style.backgroundColor = "orange"
                            statusContext.innerText = "异常"
                        } else if (bmFunSCDailyAuthScdatesEntityElement.pointContentMorningStatusId === 3) {
                            statusPoint.style.backgroundColor = "red"
                            statusContext.innerText = "重大异常"
                        } else {
                            statusContext.innerText = "未点检"
                        }
                        SCStatus.appendChild(statusPoint)
                        SCStatus.appendChild(statusContext)

                        CardMessageDiv2.appendChild(SCStatus)
                        if (!flag) {
                            let SCExExceptionCorrespondence = document.createElement("span")
                            SCExExceptionCorrespondence.className = "SCAddItemName SCAddFullName"
                            if (bmFunSCDailyAuthScdatesEntityElement.morningExceptionCorrespondence === null) {
                                SCExExceptionCorrespondence.innerText = "异常对应: 无"
                            } else {
                                SCExExceptionCorrespondence.innerText = "异常对应: " + bmFunSCDailyAuthScdatesEntityElement.morningExceptionCorrespondence

                            }
                            CardMessageDiv2.appendChild(SCExExceptionCorrespondence)
                        }


                        CardMessageDiv1.appendChild(sCTime)
                        CardMessageDiv1.appendChild(pointName)
                        CardMessageDiv1.appendChild(sCUser)


                        cardDiv.appendChild(userAuditMessageImage)
                        cardDiv.appendChild(messageName)
                        cardDiv.appendChild(CardMessageDiv1)
                        cardDiv.appendChild(CardMessageDiv2)
                        if (!flag) {

                            let CardMessageDiv3 = document.createElement("div")
                            CardMessageDiv3.className = "CardMessageDiv1 CardMessageDiv3"
                            CardMessageDiv3.style.marginLeft = "3em"

                            let SCExContext = document.createElement("span")
                            SCExContext.className = "SCAddItemName bigSpan"
                            if (bmFunSCDailyAuthScdatesEntityElement.morningEXDescription === null) {
                                SCExContext.innerText = "异常信息: 无"
                            } else {
                                SCExContext.innerText = "异常信息: " + bmFunSCDailyAuthScdatesEntityElement.morningEXDescription
                            }


                            CardMessageDiv3.appendChild(SCExContext)
                            cardDiv.appendChild(CardMessageDiv3)
                        }

                        document.getElementById("messageSidBar_ul0001").appendChild(cardDiv)


                    }
                }
            } else {
                if (bmFunSCDailyAuthScdatesEntity.scdatesEntityS[0].point === pointName && bmFunSCDailyAuthScdatesEntity.scdatesEntityS[0].date === date) {
                    let index = 0;
                    for (const bmFunSCDailyAuthScdatesEntityElement of bmFunSCDailyAuthScdatesEntity.scdatesEntityS) {
                        index++
                        let cardDiv = document.createElement("div")
                        cardDiv.setAttribute("id", "cardDiv" + index)
                        cardDiv.className = "cardDiv shadow-sm bg-white rounded"

                        let userAuditMessageImage = document.createElement("div")
                        userAuditMessageImage.className = "userAuditMessageImage"
                        userAuditMessageImage.innerText = "D" + index

                        let CardMessageDiv1 = document.createElement("div")
                        CardMessageDiv1.className = "CardMessageDiv1"

                        let messageName = document.createElement("span")
                        messageName.className = "userAuditMessageName text-muted"
                        messageName.innerText = "日常点检详细"

                        let sCTime = document.createElement("span")
                        sCTime.className = "SCAddItemName"
                        sCTime.innerText = "点检日期: " + new Date(date).toLocaleDateString()

                        let pointName = document.createElement("span")
                        pointName.className = "SCAddItemName SCAddFullName"
                        pointName.innerText = "点检内容: " + bmFunSCDailyAuthScdatesEntityElement.pointContent

                        let fullNameS = GetUser(bmFunSCDailyAuthScdatesEntityElement.pointContentMiddayUid)
                        let sCUser = document.createElement("span")
                        sCUser.className = "SCAddItemName SCAddGroup"
                        sCUser.innerText = "点检人: " + fullNameS.fullname

                        let CardMessageDiv2 = document.createElement("div")
                        CardMessageDiv2.className = "CardMessageDiv1 CardMessageDiv2"

                        let SCStatus = document.createElement("span")
                        SCStatus.className = "SCAddItemName"
                        SCStatus.innerText = "点检状态"

                        let statusPoint = document.createElement("span")
                        statusPoint.className = "statusPoint"

                        let statusContext = document.createElement("span")
                        statusContext.className = "SCAddItemName statusContext"

                        let flag = false
                        if (bmFunSCDailyAuthScdatesEntityElement.pointContentMiddayStatusId === 1) {
                            statusPoint.style.backgroundColor = "green"
                            statusContext.innerText = "正常"
                            flag = true
                        } else if (bmFunSCDailyAuthScdatesEntityElement.pointContentMiddayStatusId === 2) {
                            statusPoint.style.backgroundColor = "orange"
                            statusContext.innerText = "异常"
                        } else if (bmFunSCDailyAuthScdatesEntityElement.pointContentMiddayStatusId === 3) {
                            statusPoint.style.backgroundColor = "red"
                            statusContext.innerText = "重大异常"
                        } else {
                            statusContext.innerText = "未点检"
                        }
                        SCStatus.appendChild(statusPoint)
                        SCStatus.appendChild(statusContext)

                        CardMessageDiv2.appendChild(SCStatus)
                        if (!flag) {
                            let SCExExceptionCorrespondence = document.createElement("span")
                            SCExExceptionCorrespondence.className = "SCAddItemName SCAddFullName"
                            if (bmFunSCDailyAuthScdatesEntityElement.middayExceptionCorrespondence === null) {
                                SCExExceptionCorrespondence.innerText = "异常对应: 无"
                            } else {
                                SCExExceptionCorrespondence.innerText = "异常对应: " + bmFunSCDailyAuthScdatesEntityElement.middayExceptionCorrespondence

                            }
                            CardMessageDiv2.appendChild(SCExExceptionCorrespondence)
                        }


                        CardMessageDiv1.appendChild(sCTime)
                        CardMessageDiv1.appendChild(pointName)
                        CardMessageDiv1.appendChild(sCUser)


                        cardDiv.appendChild(userAuditMessageImage)
                        cardDiv.appendChild(messageName)
                        cardDiv.appendChild(CardMessageDiv1)
                        cardDiv.appendChild(CardMessageDiv2)
                        if (!flag) {

                            let CardMessageDiv3 = document.createElement("div")
                            CardMessageDiv3.className = "CardMessageDiv1 CardMessageDiv3"
                            CardMessageDiv3.style.marginLeft = "3em"

                            let SCExContext = document.createElement("span")
                            SCExContext.className = "SCAddItemName bigSpan"
                            if (bmFunSCDailyAuthScdatesEntityElement.middayEXDescription === null) {
                                SCExContext.innerText = "异常信息: 无"
                            } else {
                                SCExContext.innerText = "异常信息: " + bmFunSCDailyAuthScdatesEntityElement.middayEXDescription
                            }


                            CardMessageDiv3.appendChild(SCExContext)
                            cardDiv.appendChild(CardMessageDiv3)
                        }

                        document.getElementById("messageSidBar_ul0001").appendChild(cardDiv)


                    }
                }
            }
        }
    }

    //日常点检审核 结束
    //点检异常对应 开始
    let bm_fun_SCExMessage_SCExMessage

    function bm_fun_SCExMessage(obj) {
        $("#messageSidBar_ul0001").empty()
        bm_fun_SCExMessage_SCExMessage = []
        $.post("/messageCenter/GetSCExMessage", {}, function (result) {
            if (result.flag) {
                let index = 0
                bm_fun_SCExMessage_SCExMessage = result.data
                for (const datum of result.data) {
                    let mo_status = false
                    let mi_status = false
                    for (const scdatesEntity of datum.scdatesEntityS) {
                        if (scdatesEntity.pointContentMorningStatusId !== 1){
                            mo_status = true
                        }
                        if (scdatesEntity.pointContentMiddayStatusId !== 1){
                            mi_status = true
                        }
                    }
                    //早班
                    if (datum.scdatesEntityS[0].pointContentMorningStatusId != null && mo_status) {
                        index++
                        let cardDiv = document.createElement("div")
                        cardDiv.setAttribute("id", "cardDiv" + index)
                        cardDiv.className = "cardDiv shadow-sm bg-white rounded"

                        let userAuditMessageImage = document.createElement("div")
                        userAuditMessageImage.className = "userAuditMessageImage"
                        userAuditMessageImage.innerText = "EX"

                        let CardMessageDiv1 = document.createElement("div")
                        CardMessageDiv1.className = "CardMessageDiv1"

                        let messageName = document.createElement("span")
                        messageName.className = "userAuditMessageName text-muted"
                        messageName.innerText = "点检异常对应"

                        let sCTime = document.createElement("span")
                        sCTime.className = "SCAddItemName"
                        sCTime.innerText = "点检日期: " + new Date(datum.scdatesEntityS[0].date).toLocaleDateString()

                        let itemName = document.createElement("span")
                        itemName.className = "SCAddItemName SCAddFullName"
                        itemName.innerText = "点检点位: " + datum.scdatesEntityS[0].point

                        let SCSailings = document.createElement("span")
                        SCSailings.className = "SCAddItemName SCAddGroup"
                        SCSailings.innerText = "班次: 早班"

                        CardMessageDiv1.appendChild(sCTime)
                        CardMessageDiv1.appendChild(itemName)
                        CardMessageDiv1.appendChild(SCSailings)


                        let CardMessageDiv2 = document.createElement("div")
                        CardMessageDiv2.className = "CardMessageDiv1 CardMessageDiv2"

                        let SCStatus = document.createElement("span")
                        SCStatus.className = "SCAddItemName"
                        SCStatus.innerText = "点检状态"

                        let statusPoint = document.createElement("span")
                        statusPoint.className = "statusPoint"

                        let statusContext = document.createElement("span")
                        statusContext.className = "SCAddItemName statusContext"

                        SCStatus.appendChild(statusPoint)
                        SCStatus.appendChild(statusContext)
                        let flag = true
                        let breakFlag = false;
                        for (const scdatesEntity of datum.scdatesEntityS) {
                            if (scdatesEntity.pointContentMorningStatusId !== null) {
                                if (flag) {
                                    if (scdatesEntity.pointContentMorningStatusId === 1) {
                                        //正常
                                        statusPoint.style.backgroundColor = "green"
                                        statusContext.innerText = "正常"

                                    } else {
                                        if (scdatesEntity.pointContentMorningStatusId === 2) {
                                            //异常
                                            statusPoint.style.backgroundColor = "orange"
                                            statusContext.innerText = "异常"
                                            flag = false
                                        } else if (scdatesEntity.pointContentMorningStatusId === 3) {
                                            //重大异常
                                            statusPoint.style.backgroundColor = "red"
                                            statusContext.innerText = "重大异常"
                                            flag = false
                                            breakFlag = true
                                        }
                                    }
                                } else {
                                    if (scdatesEntity.pointContentMorningStatusId === 2) {
                                        //异常
                                        statusPoint.style.backgroundColor = "orange"
                                        statusContext.innerText = "异常"
                                        flag = false
                                    } else if (scdatesEntity.pointContentMorningStatusId === 3) {
                                        //重大异常
                                        statusPoint.style.backgroundColor = "red"
                                        statusContext.innerText = "重大异常"
                                        flag = false
                                        breakFlag = true;
                                    }
                                }
                            }
                            if (breakFlag) {
                                break
                            }
                        }
                        let SCExCount = document.createElement("span")
                        SCExCount.className = "SCAddItemName SCAddFullName"
                        SCExCount.innerText = "异常条目:" + datum.scdatesEntityS.length

                        let CardMessageDiv3 = document.createElement("div")
                        CardMessageDiv3.className = "CardMessageDiv1 CardMessageDiv3"

                        let acceptWorkOrders = document.createElement("button")

                        let exceptionCorrespondence = document.createElement("span")
                        exceptionCorrespondence.className = "SCAddGroup SCAddItemName"
                        if (!flag) {
                            if (datum.scdatesEntityS[0].morningExceptionCorrespondence === null) {
                                exceptionCorrespondence.innerText = "异常对应: 暂无对应"

                                acceptWorkOrders.className = "btn btn-success auditPassBtn acceptWorkOrders"
                                acceptWorkOrders.innerText = "承接工单"
                                acceptWorkOrders.setAttribute("id", "acceptWorkOrders")
                                acceptWorkOrders.addEventListener("click", function () {
                                    acceptWorkOrdersBtn("早班", datum.scdatesEntityS[0].date, datum.scdatesEntityS[0].point)
                                })
                                CardMessageDiv3.appendChild(acceptWorkOrders)
                            } else {
                                let user = GetUser(datum.scdatesEntityS[0].morningExceptionCorrespondence)
                                exceptionCorrespondence.innerText = "异常对应: " + user.fullname
                            }

                        }

                        let eXDetail = document.createElement("button")
                        eXDetail.className = "btn btn-info auditNGBtn eXDetail"
                        eXDetail.innerText = "异常详情"
                        eXDetail.setAttribute("id", "eXDetail")
                        eXDetail.addEventListener("click", function () {
                            eXDetailBtn("早班", datum.scdatesEntityS[0].date, datum.scdatesEntityS[0].point)
                        })

                        cardDiv.onmouseover = function () {
                            eXDetail.style.visibility = "visible"
                        }
                        cardDiv.onmouseout = function () {
                            eXDetail.style.visibility = "hidden"
                        }
                        if (datum.scdatesEntityS[0].morningExceptionCorrespondence !== null) {
                            acceptWorkOrders.style.visibility = "hidden"
                        } else {
                            acceptWorkOrders.style.visibility = "visible"
                        }

                        CardMessageDiv3.appendChild(eXDetail)

                        CardMessageDiv2.appendChild(SCStatus)
                        CardMessageDiv2.appendChild(SCExCount)
                        CardMessageDiv2.appendChild(exceptionCorrespondence)

                        cardDiv.appendChild(messageName)
                        cardDiv.appendChild(userAuditMessageImage)
                        cardDiv.appendChild(CardMessageDiv1)
                        cardDiv.appendChild(CardMessageDiv2)
                        cardDiv.appendChild(CardMessageDiv3)

                        document.getElementById("messageSidBar_ul0001").appendChild(cardDiv)

                    }
                    //中班
                    if (datum.scdatesEntityS[0].pointContentMiddayStatusId != null && mi_status) {
                        index++
                        let cardDiv = document.createElement("div")
                        cardDiv.setAttribute("id", "cardDiv" + index)
                        cardDiv.className = "cardDiv shadow-sm bg-white rounded"

                        let userAuditMessageImage = document.createElement("div")
                        userAuditMessageImage.className = "userAuditMessageImage"
                        userAuditMessageImage.innerText = "EX"

                        let CardMessageDiv1 = document.createElement("div")
                        CardMessageDiv1.className = "CardMessageDiv1"

                        let messageName = document.createElement("span")
                        messageName.className = "userAuditMessageName text-muted"
                        messageName.innerText = "点检异常对应"

                        let sCTime = document.createElement("span")
                        sCTime.className = "SCAddItemName"
                        sCTime.innerText = "点检日期: " + new Date(datum.scdatesEntityS[0].date).toLocaleDateString()

                        let itemName = document.createElement("span")
                        itemName.className = "SCAddItemName SCAddFullName"
                        itemName.innerText = "点检点位: " + datum.scdatesEntityS[0].point

                        let SCSailings = document.createElement("span")
                        SCSailings.className = "SCAddItemName SCAddGroup"
                        SCSailings.innerText = "班次: 中班"

                        CardMessageDiv1.appendChild(sCTime)
                        CardMessageDiv1.appendChild(itemName)
                        CardMessageDiv1.appendChild(SCSailings)


                        let CardMessageDiv2 = document.createElement("div")
                        CardMessageDiv2.className = "CardMessageDiv1 CardMessageDiv2"

                        let SCStatus = document.createElement("span")
                        SCStatus.className = "SCAddItemName"
                        SCStatus.innerText = "点检状态"

                        let statusPoint = document.createElement("span")
                        statusPoint.className = "statusPoint"

                        let statusContext = document.createElement("span")
                        statusContext.className = "SCAddItemName statusContext"

                        SCStatus.appendChild(statusPoint)
                        SCStatus.appendChild(statusContext)
                        let flag = true
                        let breakFlag = false;
                        for (const scdatesEntity of datum.scdatesEntityS) {
                            if (scdatesEntity.pointContentMiddayStatusId !== null) {
                                if (flag) {
                                    if (scdatesEntity.pointContentMiddayStatusId === 1) {
                                        //正常
                                        statusPoint.style.backgroundColor = "green"
                                        statusContext.innerText = "正常"

                                    } else {
                                        if (scdatesEntity.pointContentMiddayStatusId === 2) {
                                            //异常
                                            statusPoint.style.backgroundColor = "orange"
                                            statusContext.innerText = "异常"
                                            flag = false
                                        } else if (scdatesEntity.pointContentMiddayStatusId === 3) {
                                            //重大异常
                                            statusPoint.style.backgroundColor = "red"
                                            statusContext.innerText = "重大异常"
                                            flag = false
                                            breakFlag = true
                                        }
                                    }
                                } else {
                                    if (scdatesEntity.pointContentMiddayStatusId === 2) {
                                        //异常
                                        statusPoint.style.backgroundColor = "orange"
                                        statusContext.innerText = "异常"
                                        flag = false
                                    } else if (scdatesEntity.pointContentMiddayStatusId === 3) {
                                        //重大异常
                                        statusPoint.style.backgroundColor = "red"
                                        statusContext.innerText = "重大异常"
                                        flag = false
                                        breakFlag = true;
                                    }
                                }
                            }
                            if (breakFlag) {
                                break
                            }
                        }
                        let SCExCount = document.createElement("span")
                        SCExCount.className = "SCAddItemName SCAddFullName"
                        SCExCount.innerText = "异常条目:" + datum.scdatesEntityS.length

                        let CardMessageDiv3 = document.createElement("div")
                        CardMessageDiv3.className = "CardMessageDiv1 CardMessageDiv3"

                        let acceptWorkOrders = document.createElement("button")

                        let exceptionCorrespondence = document.createElement("span")
                        exceptionCorrespondence.className = "SCAddGroup SCAddItemName"


                        if (!flag) {
                            if (datum.scdatesEntityS[0].middayExceptionCorrespondence === null) {
                                exceptionCorrespondence.innerText = "异常对应: 暂无对应"

                                acceptWorkOrders.className = "btn btn-success auditPassBtn acceptWorkOrders"
                                acceptWorkOrders.innerText = "承接工单"
                                acceptWorkOrders.setAttribute("id", "acceptWorkOrders")
                                acceptWorkOrders.addEventListener("click", function () {
                                    acceptWorkOrdersBtn("中班", datum.scdatesEntityS[0].date, datum.scdatesEntityS[0].point)
                                })
                                CardMessageDiv3.appendChild(acceptWorkOrders)

                            } else {
                                let user = GetUser(datum.scdatesEntityS[0].middayExceptionCorrespondence)
                                exceptionCorrespondence.innerText = "异常对应: " + user.fullname
                            }

                        }


                        let eXDetail = document.createElement("button")
                        eXDetail.className = "btn btn-info auditNGBtn eXDetail"
                        eXDetail.innerText = "异常详情"
                        eXDetail.setAttribute("id", "eXDetail")
                        eXDetail.addEventListener("click", function () {
                            eXDetailBtn("中班", datum.scdatesEntityS[0].date, datum.scdatesEntityS[0].point)
                        })

                        cardDiv.onmouseover = function () {
                            eXDetail.style.visibility = "visible"
                        }
                        cardDiv.onmouseout = function () {
                            eXDetail.style.visibility = "hidden"
                        }

                        if (datum.scdatesEntityS[0].middayExceptionCorrespondence !== null) {
                            acceptWorkOrders.style.visibility = "hidden"
                        } else {
                            acceptWorkOrders.style.visibility = "visible"
                        }

                        CardMessageDiv3.appendChild(eXDetail)

                        CardMessageDiv2.appendChild(SCStatus)
                        CardMessageDiv2.appendChild(SCExCount)
                        CardMessageDiv2.appendChild(exceptionCorrespondence)

                        cardDiv.appendChild(userAuditMessageImage)
                        cardDiv.appendChild(messageName)
                        cardDiv.appendChild(CardMessageDiv1)
                        cardDiv.appendChild(CardMessageDiv2)
                        cardDiv.appendChild(CardMessageDiv3)

                        document.getElementById("messageSidBar_ul0001").appendChild(cardDiv)

                    }
                }


            }
        })
    }

    //承接工单 开始
    function acceptWorkOrdersBtn(SCSailings, date, pointName) {

        $.post("/Spot_Check_Exception/acceptWorkOrders", {
            SCSailings: SCSailings,
            date: date,
            pointName: pointName
        }, function (result) {
            if (result.flag) {
                bm_fun_SCExMessage()
            }
        })

    }

    //承接工单 结束
    //异常详情  开始

    let eXDetailBtn_SCSailings
    let eXDetailBtn_date
    let eXDetailBtn_pointName

    function eXDetailBtn(SCSailings, date, pointName) {
        eXDetailBtn_SCSailings = SCSailings
        eXDetailBtn_date = date
        eXDetailBtn_pointName = pointName
        $("#messageSidBar_ul0001").empty()
        let index = 0;

        let data = [] ;
        for (const bmFunSCExMessageSCExMessageElement of bm_fun_SCExMessage_SCExMessage) {
            if (bmFunSCExMessageSCExMessageElement.scdatesEntityS[0].point === pointName  && bmFunSCExMessageSCExMessageElement.scdatesEntityS[0].date === date){
                data = bmFunSCExMessageSCExMessageElement.scdatesEntityS
            }
        }
        console.log(data)
        for (const datum of data) {
            console.log("datum:->"+datum)
            if (SCSailings === "早班"){
            index++
            let cardDiv = document.createElement("div")
            cardDiv.setAttribute("id", "cardDiv" + index)
            cardDiv.className = "cardDiv shadow-sm bg-white rounded"

            let userAuditMessageImage = document.createElement("div")
            userAuditMessageImage.className = "userAuditMessageImage"
            userAuditMessageImage.innerText = "ED"+index

            let CardMessageDiv1 = document.createElement("div")
            CardMessageDiv1.className = "CardMessageDiv1"

            let messageName = document.createElement("span")
            messageName.className = "userAuditMessageName text-muted"
            messageName.innerText = "点检异常对应"

            let sCTime = document.createElement("span")
            sCTime.className = "SCAddItemName"
            sCTime.innerText = "点检日期: " + new Date(datum.date).toLocaleDateString()

            let itemName = document.createElement("span")
            itemName.className = "SCAddItemName SCAddFullName"
            itemName.innerText = "点检内容: " + datum.pointContent

            let SCSailings = document.createElement("span")
            SCSailings.className = "SCAddItemName SCAddGroup"
            SCSailings.innerText = "班次: 早班"

            CardMessageDiv1.appendChild(sCTime)
            CardMessageDiv1.appendChild(itemName)
            CardMessageDiv1.appendChild(SCSailings)


            let CardMessageDiv2 = document.createElement("div")
            CardMessageDiv2.className = "CardMessageDiv1 CardMessageDiv2"

            let SCStatus = document.createElement("span")
                SCStatus.className = "SCAddItemName"
                SCStatus.id = "SCStatus" + index
                SCStatus.name = index
                SCStatus.innerText = "点检状态"

            let statusPoint = document.createElement("span")
            statusPoint.className = "statusPoint"

            let statusContext = document.createElement("span")
            statusContext.className = "SCAddItemName statusContext"

            SCStatus.appendChild(statusPoint)
            SCStatus.appendChild(statusContext)


            if (datum.pointContentMorningStatusId === 1) {
                //正常
                statusPoint.style.backgroundColor = "green"
                statusContext.innerText = "正常"
            }else if (datum.pointContentMorningStatusId === 2) {
                //异常
                statusPoint.style.backgroundColor = "orange"
                statusContext.innerText = "异常"

            }else if (datum.pointContentMorningStatusId === 3) {
                //重大异常
                statusPoint.style.backgroundColor = "red"
                statusContext.innerText = "重大异常"

            }

                let selectFlag = false
                SCStatus.ondblclick = function (){
                    setSelectOption(this)
                    selectFlag = true;
                }



                let SCExContext = document.createElement("span")
                SCExContext.className = "SCAddItemName SCAddFullName SCExContext"
                if (datum.morningEXDescription == null) {
                    SCExContext.innerText = "异常描述: 无"

                }else {
                    SCExContext.innerText = "异常描述:" + datum.morningEXDescription
                    SCExContext.onmouseover = function (){
                        SCExContext.title =  datum.morningEXDescription
                    }
                }

            let CardMessageDiv3 = document.createElement("div")
            CardMessageDiv3.className = "CardMessageDiv1 CardMessageDiv3"

            let acceptWorkOrders = document.createElement("button")

            let exceptionCorrespondence = document.createElement("span")
            exceptionCorrespondence.className = "SCAddGroup SCAddItemName"

            if (datum.morningExceptionCorrespondence === null) {
                exceptionCorrespondence.innerText = "异常对应: 暂无对应"

                acceptWorkOrders.className = "btn btn-success auditPassBtn acceptWorkOrders"
                acceptWorkOrders.innerText = "承接工单"
                acceptWorkOrders.setAttribute("id", "acceptWorkOrders")

                CardMessageDiv3.appendChild(acceptWorkOrders)
            } else {
                let user = GetUser(datum.morningExceptionCorrespondence)
                exceptionCorrespondence.innerText = "异常对应: " + user.fullname
            }



            let determine = document.createElement("button")
                determine.className = "btn btn-info auditNGBtn eXDetail"
                determine.innerText = "确定"
                determine.setAttribute("id", "determine"+index)
                determine.style.visibility = "hidden"
                determine.addEventListener("click",function (){
                    determineFun(datum.date,datum.pointContent,"早班")
                })



                if (datum.morningExceptionCorrespondence !== null) {
                acceptWorkOrders.style.visibility = "hidden"
            } else {
                acceptWorkOrders.style.visibility = "visible"
            }

            CardMessageDiv3.appendChild(determine)

            CardMessageDiv2.appendChild(SCStatus)
            CardMessageDiv2.appendChild(SCExContext)
            CardMessageDiv2.appendChild(exceptionCorrespondence)

            cardDiv.appendChild(messageName)
            cardDiv.appendChild(userAuditMessageImage)
            cardDiv.appendChild(CardMessageDiv1)
            cardDiv.appendChild(CardMessageDiv2)
            cardDiv.appendChild(CardMessageDiv3)

            document.getElementById("messageSidBar_ul0001").appendChild(cardDiv)

        }
        //中班
        if (SCSailings === "中班") {
            index++
            let cardDiv = document.createElement("div")
            cardDiv.setAttribute("id", "cardDiv" + index)
            cardDiv.className = "cardDiv shadow-sm bg-white rounded"

            let userAuditMessageImage = document.createElement("div")
            userAuditMessageImage.className = "userAuditMessageImage"
            userAuditMessageImage.innerText = "ED"+index

            let CardMessageDiv1 = document.createElement("div")
            CardMessageDiv1.className = "CardMessageDiv1"

            let messageName = document.createElement("span")
            messageName.className = "userAuditMessageName text-muted"
            messageName.innerText = "点检异常对应"

            let sCTime = document.createElement("span")
            sCTime.className = "SCAddItemName"
            sCTime.innerText = "点检日期: " + new Date(datum.date).toLocaleDateString()

            let itemName = document.createElement("span")
            itemName.className = "SCAddItemName SCAddFullName"
            itemName.innerText = "点检内容: " + datum.pointContent

            let SCSailings = document.createElement("span")
            SCSailings.className = "SCAddItemName SCAddGroup"
            SCSailings.innerText = "班次: 中班"

            CardMessageDiv1.appendChild(sCTime)
            CardMessageDiv1.appendChild(itemName)
            CardMessageDiv1.appendChild(SCSailings)


            let CardMessageDiv2 = document.createElement("div")
            CardMessageDiv2.className = "CardMessageDiv1 CardMessageDiv2"

            let SCStatus = document.createElement("span")
            SCStatus.className = "SCAddItemName"
            SCStatus.id = "SCStatus" + index
            SCStatus.name = index
            SCStatus.innerText = "点检状态"

            let statusPoint = document.createElement("span")
            statusPoint.className = "statusPoint"

            let statusContext = document.createElement("span")
            statusContext.className = "SCAddItemName statusContext"

            SCStatus.appendChild(statusPoint)
            SCStatus.appendChild(statusContext)

            let selectFlag = false
            SCStatus.ondblclick = function (){
                setSelectOption(this)
                selectFlag = true;
            }





            if (datum.pointContentMiddayStatusId === 1) {
                //正常
                statusPoint.style.backgroundColor = "green"
                statusContext.innerText = "正常"
            } else if (datum.pointContentMiddayStatusId === 2) {
                    //异常
                    statusPoint.style.backgroundColor = "orange"
                    statusContext.innerText = "异常"


            } else if (datum.pointContentMiddayStatusId === 3) {
                //重大异常
                statusPoint.style.backgroundColor = "red"
                statusContext.innerText = "重大异常"
            }

            let SCExContext = document.createElement("span")
            SCExContext.className = "SCAddItemName SCAddFullName SCExContext"
            if (datum.middayEXDescription == null) {
                SCExContext.innerText = "异常描述: 无"

            }else {
                SCExContext.innerText = "异常描述:" + datum.middayEXDescription
                SCExContext.onmouseover = function (){
                    SCExContext.title =  datum.middayEXDescription
                }
            }



            let CardMessageDiv3 = document.createElement("div")
            CardMessageDiv3.className = "CardMessageDiv1 CardMessageDiv3"

            let acceptWorkOrders = document.createElement("button")

            let exceptionCorrespondence = document.createElement("span")
            exceptionCorrespondence.className = "SCAddGroup SCAddItemName"

                if (datum.middayExceptionCorrespondence === null) {
                    exceptionCorrespondence.innerText = "异常对应: 暂无对应"

                    acceptWorkOrders.className = "btn btn-success auditPassBtn acceptWorkOrders"
                    acceptWorkOrders.innerText = "承接工单"
                    acceptWorkOrders.setAttribute("id", "acceptWorkOrders")

                    CardMessageDiv3.appendChild(acceptWorkOrders)

                } else {
                    let user = GetUser(datum.middayExceptionCorrespondence)
                    exceptionCorrespondence.innerText = "异常对应: " + user.fullname
                }






            let determine = document.createElement("button")
            determine.className = "btn btn-info auditNGBtn eXDetail"
            determine.innerText = "确定"
            determine.setAttribute("id", "determine"+index)
            determine.style.visibility = "hidden"
            determine.addEventListener("click",function (){
                determineFun(datum.date,datum.pointContent,"中班")
            })





            if (datum.middayExceptionCorrespondence !== null) {
                acceptWorkOrders.style.visibility = "hidden"
            } else {
                acceptWorkOrders.style.visibility = "visible"
            }

            CardMessageDiv3.appendChild(determine)

            CardMessageDiv2.appendChild(SCStatus)
            CardMessageDiv2.appendChild(SCExContext)
            CardMessageDiv2.appendChild(exceptionCorrespondence)

            cardDiv.appendChild(userAuditMessageImage)
            cardDiv.appendChild(messageName)
            cardDiv.appendChild(CardMessageDiv1)
            cardDiv.appendChild(CardMessageDiv2)
            cardDiv.appendChild(CardMessageDiv3)

            document.getElementById("messageSidBar_ul0001").appendChild(cardDiv)

        }
    }
}

    function setSelectOption (index) {
        eXDetailBtn(eXDetailBtn_SCSailings,eXDetailBtn_date,eXDetailBtn_pointName)
        let SCStatusSelect = document.createElement("select")
        SCStatusSelect.className = "pointNameSelect"
        SCStatusSelect.id = "SCStatusSelect"

        let selectOptionNormal = document.createElement("option")
        selectOptionNormal.id = "normal"
        selectOptionNormal.value = "1"
        selectOptionNormal.innerText = "正常"

        let selectOptionEx = document.createElement("option")
        selectOptionEx.id = "ex"
        selectOptionEx.value = "2"
        selectOptionEx.innerText = "异常"

        let selectOptionBigEx = document.createElement("option")
        selectOptionBigEx.id = "bigEx"
        selectOptionBigEx.value = "3"
        selectOptionBigEx.innerText = "重大异常"

        SCStatusSelect.appendChild(selectOptionNormal)
        SCStatusSelect.appendChild(selectOptionEx)
        SCStatusSelect.appendChild(selectOptionBigEx)

        document.getElementById("determine"+index.name).style.visibility = "visible"

        $("#SCStatus"+index.name).empty()
        document.getElementById("SCStatus"+index.name).appendChild(SCStatusSelect)


    }

    //确认修改状态 开始
    function determineFun(date,pointContent,SCSailings) {
        let SCStatusSelect = document.getElementById("SCStatusSelect")
        let index = SCStatusSelect.selectedIndex
        let select = SCStatusSelect.options[index].value
        console.log(select)

        $.post("/Spot_Check_Exception/reviseStatusDetermine",{date:date,pointContent:pointContent,SCSailings:SCSailings,SCStatusSelect:select},function (result){
            if (result.flag){
                bm_fun_SCExMessage()
            }else {
                bm_fun_SCExMessage()
            }
        })
    }
    //确认修改状态 结束

    //异常详情 结束
    //


    //点检异常对应 结束



    //暴露接口 开始
    window.messageCount2 = messageCount2
    window.bm_fun_SCDailyAuth = bm_fun_SCDailyAuth
    window.bm_fun_SCExMessage = bm_fun_SCExMessage
    window.bm_fun_SCAdd = bm_fun_SCAdd
    window.returnBtn = returnBtn
    window.passButton = passButton
    window.ngButton = ngButton

    //暴露接口 结束




}(window))